<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');

$GLOBALS['TL_DCA']['tl_bds'] = array
( 
'config' => array
	(
		'dataContainer'               => 'Table',
		'enableVersioning'            => true,
	), 

    // List
    'list' => array
    (
        'sorting' => array
        (
            'mode'                    => 1,
            'fields'                  => array('title'),
            'panelLayout'             => 'limit',
        	'flag'                    => 1,
        	'child_record_callback'   => array('ProjectClass', 'listObject')
        ),
        'label' => array
        (
			'fields'                  => array('singleSRC','title'),
			'format'                  => '<img src="%s" width="150" /> %s',
        ),
        'global_operations' => array
		(
			'all' => array
			(
				'label'               => &$GLOBALS['TL_LANG']['MSC']['all'],
				'href'                => 'act=select',
				'class'               => 'header_edit_all',
				'attributes'          => 'onclick="Backend.getScrollOffset();" accesskey="e"'
			)
		),
        'operations' => array
		(
			'edit' => array
			(
				'label'               => &$GLOBALS['TL_LANG']['MSC']['edit'],
				'href'                => 'act=edit',
				'icon'                => 'edit.gif',
			),
			'copy' => array
			(
				'label'               => &$GLOBALS['TL_LANG']['MSC']['copy'],
				'href'                => 'act=copy',
				'icon'                => 'copy.gif',
			),
			'delete' => array
			(
				'label'               => &$GLOBALS['TL_LANG']['tl_news']['delete'],
				'href'                => 'act=delete',
				'icon'                => 'delete.gif',
				'attributes'          => 'onclick="if (!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\')) return false; Backend.getScrollOffset();"',
			),
			'toggle' => array
			(
				'label'               => &$GLOBALS['TL_LANG']['tl_news']['toggle'],
				'icon'                => 'visible.gif',
				'attributes'          => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"',
				'button_callback'     => array('BDSClass', 'toggleIcon')
			),
			'show' => array
			(
				'label'               => &$GLOBALS['TL_LANG']['tl_news']['show'],
				'href'                => 'act=show',
				'icon'                => 'show.gif'
			)
		)
    ),

    // Palettes
	'palettes' => array
	(
				'__selector__'                => array('addImage'),
				'default'                     => '{title_legend},title,gia,diachi,sotang,dientich,phaply;loaibds,type;{des_legend},text;{lienhe_legend},lienhe;{image_legend},addImage;{publish_legend};{date_legend},date,time;published,start,stop'
	),
	    // Subpalettes
	'subpalettes' => array
	(
		'addImage'                    => 'singleSRC',
	),
    // Fields
    'fields' => array
    (
    	'title' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['title'],
			'search'                  => true,
			'flag'                    => 1,
			'inputType'               => 'text',
			'eval'                    => array('mandatory'=>true, 'maxlength'=>255, 'tl_class'=>'w50')
		),
		'type'  => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['type'],
            'inputType'               => 'select',
            'options_callback'        => array('BDSClass', 'getType'),
            'search'                  => true,
            'sorting'                 => true,
            'filter'                  => true,
            'exclude'                 => true,
            'flag'                    => 11,
            'eval'                    => array('mandatory'=>true, 'tl_class'=>'w50')
        ),
        'date' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['date'],
			'default'                 => time(),
			'exclude'                 => true,
			'filter'                  => true,
			'sorting'                 => true,
			'flag'                    => 8,
			'inputType'               => 'text',
			'eval'                    => array('rgxp'=>'date', 'doNotCopy'=>true, 'datepicker'=>true, 'tl_class'=>'w50 wizard')
		),
		'time' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['time'],
			'default'                 => time(),
			'exclude'                 => true,
			'inputType'               => 'text',
			'eval'                    => array('rgxp'=>'time', 'doNotCopy'=>true, 'tl_class'=>'w50')
		),
		'text' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['text'],
			'exclude'                 => true,
			'inputType'               => 'textarea',
			'eval'                    => array('mandatory'=>true, 'rte'=>'tinyMCE', 'tl_class'=>'clr')
		),
		'lienhe' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['lienhe'],
			'exclude'                 => true,
			'inputType'               => 'textarea',
			'eval'                    => array('mandatory'=>true, 'rte'=>'tinyMCE', 'tl_class'=>'clr')
		),
		'gia' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['gia'],
			'search'                  => true,
			'flag'                    => 1,
			'inputType'               => 'text',
			'eval'                    => array('maxlength'=>255, 'tl_class'=>'w50')
		),
		'addImage' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['addImage'],
			'exclude'                 => true,
			'inputType'               => 'checkbox',
			'eval'                    => array('submitOnChange'=>true)
		),
		'singleSRC' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['singleSRC'],
			'exclude'                 => true,
			'inputType'               => 'fileTree',
			'eval'                    => array('fieldType'=>'radio', 'files'=>true, 'filesOnly'=>true, 'mandatory'=>true)
		),
		'diachi' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['diachi'],
			'search'                  => true,
			'flag'                    => 1,
			'inputType'               => 'text',
			'eval'                    => array('maxlength'=>255, 'tl_class'=>'w50')
		),
		'loaibds'  => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['loaibds'],
            'inputType'               => 'select',
            'options_callback'        => array('BDSClass', 'getLoaiBDS'),
            'search'                  => true,
            'sorting'                 => true,
            'filter'                  => true,
            'exclude'                 => true,
            'flag'                    => 11,
            'eval'                    => array('tl_class'=>'w50')
        ),
		'sotang' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['sotang'],
			'search'                  => true,
			'flag'                    => 1,
			'inputType'               => 'text',
			'eval'                    => array('maxlength'=>255, 'tl_class'=>'w50')
		),
		'dientich' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['dientich'],
			'search'                  => true,
			'flag'                    => 1,
			'inputType'               => 'text',
			'eval'                    => array('maxlength'=>255, 'tl_class'=>'w50')
		),
		'phaply' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['phaply'],
			'search'                  => true,
			'flag'                    => 1,
			'inputType'               => 'text',
			'eval'                    => array('maxlength'=>255, 'tl_class'=>'w50')
		),
		'published' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['published'],
			'exclude'                 => true,
			'filter'                  => true,
			'flag'                    => 1,
			'inputType'               => 'checkbox',
			'eval'                    => array('doNotCopy'=>true)
		),
		'start' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['start'],
			'exclude'                 => true,
			'inputType'               => 'text',
			'eval'                    => array('rgxp'=>'datim', 'datepicker'=>true, 'tl_class'=>'w50 wizard')
		),
		'stop' => array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_bds']['stop'],
			'exclude'                 => true,
			'inputType'               => 'text',
			'eval'                    => array('rgxp'=>'datim', 'datepicker'=>true, 'tl_class'=>'w50 wizard')
		)
    )
);
class BDSClass extends Backend
{
    public function getLoaiBDS($dc)
    {
    	$arrType = array();
    	$arrType[1] = 'Nhà phố';
    	$arrType[2] = 'Căn hộ';
    	$arrType[3] = 'Biệt thự';
    	$arrType[4] = 'Đất dự án';
    	return $arrType;
    }
    public function getType($dc)
    {
    	$arrType = array();
    	$arrType[1] = 'Cần bán';
    	$arrType[2] = 'Cần mua';
    	$arrType[3] = 'Cho thuê';
    	$arrType[4] = 'Cần thuê';
    	return $arrType;
    }
    public function listObject($arrRow)
	{
		
		return "<img src='".$arrRow['singleSRC']."' width='150' /> ".$arrRow['title']."\n";
	}
	public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
	{
		if (strlen($this->Input->get('tid')))
		{
			$this->toggleVisibility($this->Input->get('tid'), ($this->Input->get('state') == 1));
			$this->redirect($this->getReferer());
		}

		$href .= '&amp;tid='.$row['id'].'&amp;state='.($row['published'] ? '' : 1);

		if (!$row['published'])
		{
			$icon = 'invisible.gif';
		}		

		return '<a href="'.$this->addToUrl($href).'" title="'.specialchars($title).'"'.$attributes.'>'.$this->generateImage($icon, $label).'</a> ';
	}
	public function toggleVisibility($intId, $blnVisible)
	{
		$this->createInitialVersion('tl_bds', $intId);


		// Update the database
		$this->Database->prepare("UPDATE tl_bds SET tstamp=". time() .", published='" . ($blnVisible ? 1 : '') . "' WHERE id=?")
					   ->execute($intId);

		$this->createNewVersion('tl_bds', $intId);

	}
}

?>
